package com.anxinr.controller.user;

import com.anxinr.pojo.dto.OrderDTO;
import com.anxinr.pojo.entity.OrderGoods;
import com.anxinr.result.Result;
import com.anxinr.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单交互层
 * @author anxinr
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService ;

    /**
     * 用户下单
     * @param orderDTO
     * @return Result
     */
    @PostMapping("/placeOrder")
    public Result placeOrder(@RequestBody OrderDTO orderDTO){
        orderService.saveOrderInfo(orderDTO) ;
        return Result.success() ;
    }

    /**
     * 我的订单
     * @Param id
     * @return Result
     */
    @GetMapping("/myOrder")
    public Result myOrder(@RequestParam("userId") Long userId){
        List<OrderDTO> list = orderService.getMyOrder(userId) ;
        return new Result(list) ;
    }

    /**
     * 订单详细信息
     * @Param goodsId
     * @return Result
     */
    @GetMapping("/myOrderDetail")
    public Result myOrderDetail(@RequestParam("goodsId") Long goodsId){
        OrderGoods goods = orderService.myOrderDetail(goodsId) ;
        return new Result(goods) ;
    }

    /**
     * 配送订单
     * @Param orderId
     * @return Result
     */
    @GetMapping("/sendOrder")
    public Result sendOrder(@RequestParam("orderId") Long orderId){
        orderService.sendOrder(orderId) ;
        return Result.success() ;
    }

    /**
     * 已完成订单
     * @Param orderId
     * @return Result
     */
    @GetMapping("/successOrder")
    public Result successOrder(@RequestParam("orderId") Long orderId){
        orderService.successOrder(orderId) ;
        return Result.success() ;
    }
}
